package com.kevin.v2.spring.formework.aop.aspect;

import com.kevin.v2.spring.formework.aop.intercept.KvMethodInterceptor;
import com.kevin.v2.spring.formework.aop.intercept.KvMethodInvocation;

import java.lang.reflect.Method;

public class KvMethodThrowingAdvice extends KvAbstractAspectAdvice implements KvMethodInterceptor {

   private String throwingName;

   KvJoinPoint kvJoinPoint;

   public KvMethodThrowingAdvice (Method aspectMethod, Object aspectTarget) {
      super(aspectMethod, aspectTarget);
   }

   @Override
   public Object invoke (KvMethodInvocation methodInvocation) throws Throwable {
      Object returnValue=null;
      try {
          returnValue = methodInvocation.proceed();
         this.kvJoinPoint = methodInvocation;
         return returnValue;
      } catch (Exception e) {
         e.printStackTrace();
         invokeAdviceMethod(kvJoinPoint, returnValue, e.getCause());
         throw e;
      }
   }

   public String getThrowingName () {
      return throwingName;
   }

   public void setThrowingName (String throwingName) {
      this.throwingName = throwingName;
   }
}
